#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

typedef int ElementType;
typedef struct QUEUE Queue;
struct QUEUE{
	ElementType elm;
	Queue *next;
	Queue *tail;
};

Queue *QueueInit(void);
_Bool QueueEmpty(Queue*);
void EnQueue(Queue*,ElementType);
ElementType DeQueue(Queue*);

int main(void){
	int N,M;
	scanf("%d %d",&N,&M);
	int ret[N], g[N][N], indegree[N];
	for(int i=0;i<N;i++){
		ret[i]=0;
		indegree[i]=0;
		for(int j=0;j<N;j++){
			g[i][j]=-1;	
		}
	}
	int s,e,l;
	for(int i=0;i<M;i++){
		scanf("%d %d %d",&s,&e,&l);
		indegree[e]++;
		g[s][e]=l;
	}
//
	Queue *q=QueueInit();
	ElementType elm;
	for(int i=0;i<N;i++)
		if( indegree[i] == 0 )
			EnQueue(q,i);
	while( !QueueEmpty(q) ){
		elm=DeQueue(q);
		for(int i=0;i<N;i++){
			if( g[elm][i]!=-1 ){
				ret[i]=ret[elm]+g[elm][i]>ret[i]?ret[elm]+g[elm][i]:ret[i];
				g[elm][i]=-1;
				if( 0 == --indegree[i] ){
					EnQueue(q,i);
				}
			}
		}
	}
	int max=-1;
	for(int i=0;i<N;i++){
		if( indegree[i]!=0 ){
			printf("Impossible");
			return 0;
		}
		if( ret[i]>max )max=ret[i];
	}
	printf("%d",max);
/*
printf("\n");
for(int i=0;i<N;i++){
	printf("%3d",ret[i]);
}
printf("\n");
for(int i=0;i<N;i++){
	printf("%3d",indegree[i]);
}*/
	return 0;
}



Queue *QueueInit(void){
	Queue *q=malloc(sizeof(Queue));
	q->next=NULL;
	q->tail=q;
	return q;
}
_Bool QueueEmpty(Queue *q){
	if(q->next)return false;
	return true;
}
void EnQueue(Queue *q,ElementType e){
	Queue *new=malloc(sizeof(Queue));
	new->elm=e;
	new->next=NULL;
	q->tail->next=new;
	q->tail=new;
	return;
}
ElementType DeQueue(Queue *q){
	ElementType e=q->next->elm;
	Queue *t=q->next;
	q->next=q->next->next;
	free(t);
	if( !q->next )
		q->tail=q;
	return e;
}
